//
//  BillTableViewCell.m
//  AAIM
//
//  Created by 远的小布丁 on 2020/1/26.
//  Copyright © 2020 AAIM. All rights reserved.
//

#import "BillTableViewCell.h"

@implementation BillTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setShowUI{
    self.contentView.backgroundColor = KHEXCOLOR(@"#F4F4F4");
    [self.contentView addSubview:self.backView];
    [self.backView addSubview:self.titleLbl];
    [self.backView addSubview:self.payWayLbl];
//    [self.backView addSubview:self.BeneficiaryLbl];
//    [self.backView addSubview:self.BeneficiaryUserNickNameLbl];
//    [self.backView addSubview:self.payMoneyLbl];
//    [self.backView addSubview:self.moneyLbl];
//    [self.backView addSubview:self.stautsLbl];
//    [self.backView addSubview:self.stautsStr];
    [self.backView addSubview:self.remarkLbl];
    [self.backView addSubview:self.remarkStr];
    [self.backView addSubview:self.line2];
    [self.backView addSubview:self.rightImg];
    [self.backView addSubview:self.checkDetailLbl];

    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(kScreenWidth-30);
        make.bottom.equalTo(self.contentView);
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
    }];
    [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(self.backView.width-32, 21.f));
        make.top.equalTo(self.backView).offset(16);
        make.left.equalTo(self.backView).offset(16);
        make.right.equalTo(self.backView).offset(-16);
    }];
    [self.payWayLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(self.backView.width-32, 17.f));
        make.top.equalTo(self.titleLbl.mas_bottom).offset(9);
        make.left.equalTo(self.backView).offset(16);
        make.right.equalTo(self.backView).offset(-16);
    }];
//    [self.BeneficiaryLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(60, 17.f));
//        make.top.equalTo(self.payWayLbl.mas_bottom).offset(14);
//        make.left.equalTo(self.backView).offset(16);
//    }];
//    [self.BeneficiaryUserNickNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.BeneficiaryLbl.mas_centerY);
//        make.left.equalTo(self.BeneficiaryLbl.mas_right).offset(6);
//        make.right.equalTo(self.backView).offset(-16);
//        make.height.offset(17);
//    }];
//    [self.payMoneyLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//           make.size.mas_equalTo(CGSizeMake(60, 17.f));
//           make.top.equalTo(self.BeneficiaryLbl.mas_bottom).offset(14);
//           make.left.equalTo(self.backView).offset(16);
//       }];
//       [self.moneyLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//           make.centerY.equalTo(self.payMoneyLbl.mas_centerY);
//           make.left.equalTo(self.payMoneyLbl.mas_right).offset(6);
//           make.right.equalTo(self.backView).offset(-16);
//           make.height.offset(17);
//       }];
//    [self.stautsLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//           make.size.mas_equalTo(CGSizeMake(60, 17.f));
//           make.top.equalTo(self.payMoneyLbl.mas_bottom).offset(14);
//           make.left.equalTo(self.backView).offset(16);
//       }];
//       [self.stautsStr mas_makeConstraints:^(MASConstraintMaker *make) {
//           make.centerY.equalTo(self.stautsLbl.mas_centerY);
//           make.left.equalTo(self.stautsLbl.mas_right).offset(6);
//           make.right.equalTo(self.backView).offset(-16);
//           make.height.offset(17);
//       }];
    [self.rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
               make.size.mas_equalTo(CGSizeMake(15, 15));
               make.bottom.equalTo(self.backView.mas_bottom).offset(-15);
               make.right.equalTo(self.backView).offset(-10);
           }];
    [self.checkDetailLbl mas_makeConstraints:^(MASConstraintMaker *make) {
               make.size.mas_equalTo(CGSizeMake(60, 18.f));
               make.bottom.equalTo(self.backView.mas_bottom).offset(-15);
               make.left.equalTo(self.backView).offset(16);
               make.right.equalTo(self.rightImg).offset(-16);
    }];
    [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.checkDetailLbl.mas_top).offset(-14);
        make.left.equalTo(self.backView);
        make.right.equalTo(self.backView);
        make.height.offset(1.f);
    }];
    [self.remarkLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 17.f));
            make.bottom.equalTo(self.line2.mas_top).offset(-14);
            make.left.equalTo(self.backView).offset(16);
        }];
    [self.remarkStr mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.remarkLbl.mas_centerY);
            make.left.equalTo(self.remarkLbl.mas_right).offset(6);
            make.right.equalTo(self.backView).offset(-16);
            make.height.offset(17);
        }];
    
}

- (void)setModel:(BillModel *)model{
    
    _model = model;
    _titleLbl.text = model.title;
    _remarkStr.text = model.remark;
    _payWayLbl.text = model.describe;
    NSMutableDictionary * dicData = [NSMutableDictionary dictionary];
    for (NSDictionary * dic in model.parameterJson) {
        NSString * key = dic[@"k"];
        NSString * value = dic[@"v"];
        [dicData setValue:value forKey:key];
    }
    for (UILabel * lb in self.backView.subviews) {
        if (lb.tag >=10000) {
            [lb removeFromSuperview];
        }
    }
    NSArray * keyAry = [dicData allKeys];
    for (int i = 0; i<keyAry.count; i++) {
        UILabel * lbl = [[UILabel alloc]initWithFrame:CGRectMake(16, 77+(18+14)*i, 60.f, 18)];
        lbl.font = kMainFont(12);
        lbl.textColor = KHEXCOLOR(@"#7A7A7A");
        lbl.text = keyAry[i];
        lbl.tag = 10000+i;
        [self.backView addSubview:lbl];
      UILabel * contentLbl = [[UILabel alloc]initWithFrame:CGRectMake(lbl.right+6, 77+(18+14)*i, kScreenWidth-15-15-60-6, 18)];
        contentLbl.font = kMainFont(13);
        contentLbl.tag = 10000+i;
        contentLbl.textColor = KHEXCOLOR(AllBackColor_titleColor);
        contentLbl.text = dicData[keyAry[i]];
        [self.backView addSubview:contentLbl];
    }
    
    
}

- (UIView *)line2{
    if (!_line2) {
        _line2 = [[UIView alloc]init];
        _line2.backgroundColor = KHEXCOLOR(@"#E0E0E0");
    }
    return _line2;
}

-(UIImageView *)rightImg{
    if (!_rightImg) {
        _rightImg = [[UIImageView alloc]init];
        _rightImg.image = [UIImage imageNamed:@"返回键"];
    }
    return _rightImg;
}
-(UILabel *)remarkStr{
    if (!_remarkStr) {
        _remarkStr = [[UILabel alloc]init];
        _remarkStr.font = kMainFont(13);
        _remarkStr.textColor = KHEXCOLOR(AllBackColor_titleColor);
        _remarkStr.text = @"无";
    }
    return _remarkStr;
}
-(UILabel *)stautsStr{
    if (!_stautsStr) {
        _stautsStr = [[UILabel alloc]init];
        _stautsStr.font = kMainFont(13);
        _stautsStr.textColor = KHEXCOLOR(AllBackColor_titleColor);
        _stautsStr.text = @"已成功交易";
    }
    return _stautsStr;
}
-(UILabel *)moneyLbl{
    if (!_moneyLbl) {
        _moneyLbl = [[UILabel alloc]init];
        _moneyLbl.font = kMainFont(13);
        _moneyLbl.textColor = KHEXCOLOR(AllBackColor_titleColor);
        _moneyLbl.text = @"0.00元";
    }
    return _moneyLbl;
}
-(UILabel *)BeneficiaryUserNickNameLbl{
    if (!_BeneficiaryUserNickNameLbl) {
        _BeneficiaryUserNickNameLbl = [[UILabel alloc]init];
        _BeneficiaryUserNickNameLbl.font = kMainFont(13);
        _BeneficiaryUserNickNameLbl.textColor = KHEXCOLOR(AllBackColor_titleColor);
        _BeneficiaryUserNickNameLbl.text = @"用户昵称";
    }
    return _BeneficiaryUserNickNameLbl;
}
-(UILabel *)checkDetailLbl{
    if (!_checkDetailLbl) {
        _checkDetailLbl = [[UILabel alloc]init];
        _checkDetailLbl.font = kMainFont(13);
        _checkDetailLbl.textColor = KHEXCOLOR(AllBackColor_titleColor);
        _checkDetailLbl.text = @"查看详情";
    }
    return _checkDetailLbl;
}
-(UILabel *)remarkLbl{
    if (!_remarkLbl) {
        _remarkLbl = [[UILabel alloc]init];
        _remarkLbl.font = kMainFont(12);
        _remarkLbl.textColor = KHEXCOLOR(@"#7A7A7A");
        _remarkLbl.text = @"备注：";
    }
    return _remarkLbl;
}
-(UILabel *)stautsLbl{
    if (!_stautsLbl) {
        _stautsLbl = [[UILabel alloc]init];
        _stautsLbl.font = kMainFont(12);
        _stautsLbl.textColor = KHEXCOLOR(@"#7A7A7A");
        _stautsLbl.text = @"交易状态：";
    }
    return _stautsLbl;
}
-(UILabel *)payMoneyLbl{
    if (!_payMoneyLbl) {
        _payMoneyLbl = [[UILabel alloc]init];
        _payMoneyLbl.font = kMainFont(12);
        _payMoneyLbl.textColor = KHEXCOLOR(@"#7A7A7A");
        _payMoneyLbl.text = @"缴费金额：";
    }
    return _payMoneyLbl;
}
-(UILabel *)BeneficiaryLbl{
    if (!_BeneficiaryLbl) {
        _BeneficiaryLbl = [[UILabel alloc]init];
        _BeneficiaryLbl.font = kMainFont(12);
        _BeneficiaryLbl.textColor = KHEXCOLOR(@"#7A7A7A");
        _BeneficiaryLbl.text = @"收款方：";
    }
    return _BeneficiaryLbl;
}

-(UILabel *)payWayLbl{
    if (!_payWayLbl) {
        _payWayLbl = [[UILabel alloc]init];
        _payWayLbl.font = kMainFont(12);
        _payWayLbl.textColor = KHEXCOLOR(@"#7A7A7A");
        _payWayLbl.text = @"本次通过微信支付";
    }
    return _payWayLbl;
}
-(UILabel *)titleLbl{
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc]init];
        _titleLbl.font = kMainFont(15);
        _titleLbl.textColor = KHEXCOLOR(AllBackColor_titleColor);
        _titleLbl.text = @"支付凭证";
    }
    return _titleLbl;
}
- (UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc]init];
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.layer.cornerRadius =8;
        _backView.layer.masksToBounds = YES;
        
    }
    return _backView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
